﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;

public class TrailGhost : MonoBehaviour
{
    [CompilerGenerated]
    private static Action<Animator> <>f__am$cache3;
    public float interval = 0.05f;
    public Animator model;
    private Queue<Animator> trail = new Queue<Animator>();

    [DebuggerHidden]
    private IEnumerator _TrailGhost()
    {
        return new <_TrailGhost>c__Iterator3 { <>f__this = this };
    }

    private void OnDisable()
    {
        base.StopAllCoroutines();
        if (<>f__am$cache3 == null)
        {
            <>f__am$cache3 = delegate (Animator x) {
                if ((x != null) && x.gameObject.activeSelf)
                {
                    x.Recycle<Animator>();
                }
            };
        }
        this.trail.Foreach<Animator>(<>f__am$cache3);
    }

    private void OnEnable()
    {
        base.StartCoroutine(this._TrailGhost());
    }

    private void Start()
    {
        if (this.model == null)
        {
            this.model = base.GetComponentInChildren<Animator>();
        }
    }

    [CompilerGenerated]
    private sealed class <_TrailGhost>c__Iterator3 : IDisposable, IEnumerator, IEnumerator<object>
    {
        internal object $current;
        internal int $PC;
        internal TrailGhost <>f__this;
        internal FadeChildRenderersOnEnable <fade>__1;
        internal Animator <ins>__0;

        internal void <>m__6D()
        {
            this.<>f__this.trail.Dequeue().Recycle<Animator>();
        }

        [DebuggerHidden]
        public void Dispose()
        {
            this.$PC = -1;
        }

        public bool MoveNext()
        {
            uint num = (uint) this.$PC;
            this.$PC = -1;
            switch (num)
            {
                case 0:
                    if (this.<>f__this.model != null)
                    {
                        break;
                    }
                    goto Label_014D;

                case 1:
                    break;
                    this.$PC = -1;
                    goto Label_014D;

                default:
                    goto Label_014D;
            }
            this.<ins>__0 = this.<>f__this.model.Spawn<Animator>();
            this.<fade>__1 = this.<ins>__0.gameObject.GetOrAddComponent<FadeChildRenderersOnEnable>();
            this.<fade>__1.startValue = 1f;
            this.<fade>__1.endValue = 0f;
            this.<fade>__1.duration = 0.3f;
            this.<ins>__0.Stop();
            this.<ins>__0.transform.position = this.<>f__this.model.transform.position;
            this.<ins>__0.transform.eulerAngles = this.<>f__this.model.transform.eulerAngles;
            this.<>f__this.trail.Enqueue(this.<ins>__0);
            this.<>f__this.StartWaitForSeconds(0.3f, new Action(this.<>m__6D));
            this.$current = new WaitForSeconds(this.<>f__this.interval);
            this.$PC = 1;
            return true;
        Label_014D:
            return false;
        }

        [DebuggerHidden]
        public void Reset()
        {
            throw new NotSupportedException();
        }

        object IEnumerator<object>.Current
        {
            [DebuggerHidden]
            get
            {
                return this.$current;
            }
        }

        object IEnumerator.Current
        {
            [DebuggerHidden]
            get
            {
                return this.$current;
            }
        }
    }
}

